﻿@model AddressModel
@using Nop.Web.Framework;
@using Nop.Web.Models.Common;
<script type="text/javascript">
     $(function() {
            $("#@Html.FieldIdFor(model => model.CountryId)").change(function() {
                var selectedItem = $(this).val();
                var ddlStates = $("#@Html.FieldIdFor(model => model.StateProvinceId)");
                var statesProgress = $("#states-loading-progress");
                statesProgress.show();
                $.ajax({
                    cache: false,
                    type: "GET",
                    url: "@(Url.RouteUrl("GetStatesByCountryId"))",
                    data: { "countryId": selectedItem, "addEmptyStateIfRequired": "true" },
                    success: function (data) {
                        ddlStates.html('');
                        $.each(data, function(id, option) {
                            ddlStates.append($('<option></option>').val(option.id).html(option.name));
                        });
                        statesProgress.hide();
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        alert('Failed to retrieve states.');
                        statesProgress.hide();
                    }  
                });
            });
        });
</script>
@Html.HiddenFor(model => model.Id)
<table>
    <tr>
        <td>
            @Html.LabelFor(model => model.FirstName):
        </td>
        <td>
            @Html.EditorFor(model => model.FirstName)
            @Html.RequiredHint()
            @Html.ValidationMessageFor(model => model.FirstName)
        </td>
    </tr>
    <tr>
        <td>
            @Html.LabelFor(model => model.LastName):
        </td>
        <td>
            @Html.EditorFor(model => model.LastName)
            @Html.RequiredHint()
            @Html.ValidationMessageFor(model => model.LastName)
        </td>
    </tr>
    <tr>
        <td>
            @Html.LabelFor(model => model.Email):
        </td>
        <td>
            @Html.EditorFor(model => model.Email)
            @Html.RequiredHint()
            @Html.ValidationMessageFor(model => model.Email)
        </td>
    </tr>
    <tr>
        <td>
            @Html.LabelFor(model => model.Company):
        </td>
        <td>
            @Html.EditorFor(model => model.Company)
            @Html.ValidationMessageFor(model => model.Company)
        </td>
    </tr>
    <tr>
        <td>
            @Html.LabelFor(model => model.CountryId):
        </td>
        <td>
            @Html.DropDownListFor(model => model.CountryId, Model.AvailableCountries)
            @Html.RequiredHint()
            @Html.ValidationMessageFor(model => model.CountryId)
        </td>
    </tr>
    <tr>
        <td>
            @Html.LabelFor(model => model.StateProvinceId):
        </td>
        <td>
            @Html.DropDownListFor(model => model.StateProvinceId, Model.AvailableStates)
            <span id="states-loading-progress" style="display: none;">@T("Common.Wait...")
                <img src='@Url.Content("~/Content/Images/ajax_loader_small.gif")' alt="@T("Common.Wait...")" />
            </span>
            @Html.ValidationMessageFor(model => model.StateProvinceId)
        </td>
    </tr>
    <tr>
        <td>
            @Html.LabelFor(model => model.City):
        </td>
        <td>
            @Html.EditorFor(model => model.City)
            @Html.RequiredHint()
            @Html.ValidationMessageFor(model => model.City)
        </td>
    </tr>
    <tr>
        <td>
            @Html.LabelFor(model => model.Address1):
        </td>
        <td>
            @Html.EditorFor(model => model.Address1)
            @Html.RequiredHint()
            @Html.ValidationMessageFor(model => model.Address1)
        </td>
    </tr>
    <tr>
        <td>
            @Html.LabelFor(model => model.Address2):
        </td>
        <td>
            @Html.EditorFor(model => model.Address2)
            @Html.ValidationMessageFor(model => model.Address2)
        </td>
    </tr>
    <tr>
        <td>
            @Html.LabelFor(model => model.ZipPostalCode):
        </td>
        <td>
            @Html.EditorFor(model => model.ZipPostalCode)
            @Html.RequiredHint()
            @Html.ValidationMessageFor(model => model.ZipPostalCode)
        </td>
    </tr>
    <tr>
        <td>
            @Html.LabelFor(model => model.PhoneNumber):
        </td>
        <td>
            @Html.EditorFor(model => model.PhoneNumber)
            @Html.RequiredHint()
            @Html.ValidationMessageFor(model => model.PhoneNumber)
        </td>
    </tr>
    <tr>
        <td>
            @Html.LabelFor(model => model.FaxNumber):
        </td>
        <td>
            @Html.EditorFor(model => model.FaxNumber)
            @Html.ValidationMessageFor(model => model.FaxNumber)
        </td>
    </tr>
</table>
